﻿namespace MsForgeReboot.Services.Tests {
    #region Usings

    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Globalization;
    using MsForgeReboot.Framework.Entities;
    using MsForgeReboot.Framework.Interfaces;
    using MsForgeReboot.Services.Tests.Fakes;

    #endregion

    internal class TestDataGenerator {
        public static InMemoryDbSet<User> GetFakeUserInstances(int count) {
            var list = new InMemoryDbSet<User>();
            for (var i = 1; i < count + 1; i++) {
                list.Add(
                    new User {
                                 Id = i,
                                 PublicName = "User " + i,
                                 Username = string.Format("user-name-{0}@domain{1}.com", i, i),
                                 ReceiveNotifications = true,
                                 IsValidated = true
                             });
            }

            return list;
        }

        /// <summary>
        ///     Gets the fake user group instances.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public static InMemoryDbSet<UserGroup> GetFakeUserGroupInstances(int count) {
            var list = new InMemoryDbSet<UserGroup>();
            for (var i = 1; i < count + 1; i++) {
                list.Add(
                    new UserGroup {
                                      Author = new User(),
                                      Body = "Description " + i.ToString(CultureInfo.InvariantCulture),
                                      Members = new List<User>(),
                                      Id = i,
                                      Events = new List<Event>(),
                                      Title = "User Group " + i,
                                      UrlPointer = "user-group-" + i,
                                      Published = DateTime.Now.AddDays(i * -1)
                                  });
            }

            return list;
        }

        /// <summary>
        ///     Gets the fake event instances.
        /// </summary>
        /// <param name="count">total number of events.</param>
        /// <param name="upcoming">Number of upcoming events.</param>
        /// <returns></returns>
        public static IDbSet<Event> GetFakeEventInstances(int count, int upcoming) {
            var list = new InMemoryDbSet<Event>();
            for (var i = 1; i < upcoming + 1; i++) {
                list.Add(
                    new Event {
                                  Id = i,
                                  Title = "Event Title " + i,
                                  Author = new User(),
                                  Body = "event Description " + i.ToString(CultureInfo.InvariantCulture),
                                  UrlPointer = "event-title-" + i,
                                  Address =
                                      new Address {
                                                      City = "Test City",
                                                      Country = "Test Country",
                                                      Street = "Test Street",
                                                      StreetNumber = "12b"
                                                  },
                                  Topic = "Test Topic " + i,
                                  Begin = DateTime.Now.AddDays(i),
                                  Published = DateTime.Now.AddDays(i * -3).AddHours(i * -2)
                              });
            }

            for (var i = upcoming + 1; i < count + 1; i++) {
                list.Add(
                    new Event {
                                  Id = i,
                                  Title = "Event Title " + i,
                                  Author = new User(),
                                  Body = "event Description " + i.ToString(CultureInfo.InvariantCulture),
                                  UrlPointer = "event-title-" + i,
                                  Address =
                                      new Address {
                                                      City = "Test City",
                                                      Country = "Test Country",
                                                      Street = "Test Street",
                                                      StreetNumber = "12b"
                                                  },
                                  Topic = "Test Topic " + i,
                                  Begin = DateTime.Now.AddDays(i * -1),
                                  Published = DateTime.Now.AddDays(i * -2)
                              });
            }

            return list;
        }

        /// <summary>
        /// Generates a fake TownCrierEvent object to be used for testing the 
        /// TownCrier EventDeliveryService.
        /// </summary>
        public static Event GetFakeTownCrierEvent() {
            Event result = new Event();

            result.Id = new Random().Next();
            result.IsStreamingEvent = false;
            result.Published = DateTime.Now;
            result.Begin = DateTime.Now.AddDays(4);
            result.End = DateTime.Now.AddDays(4).AddHours(3);
            result.Topic = "Test topic for TC";
            result.Address = new Address {
                City = "Belgrade",
                Country = "Serbia",
                Street = "Spanskih boraca",
                StreetNumber = "3"
            };
            result.Body = "Test body";

            //result.SelectedChannels = new List<IChannel>();

            return result;
        }

    }
}
